package io.renren.modules.app.controller.user.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.UserEntity;
import io.renren.modules.app.entity.YcUserEntity;
import io.renren.modules.app.entity.YcUserResumeEntity;
import io.renren.modules.app.service.UserService;
import io.renren.modules.app.service.YcUserResumeService;
import io.renren.modules.app.service.YcUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;




@RestController
@RequestMapping("148user")
public class UserController {
    @Autowired
    UserService userService;


    @PostMapping("/loginUser")
    public R loginUser(@RequestParam Map<String, Object> map){
        String name= (String) map.get("loginAccountName");
        String password= (String) map.get("loginPassword");
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        System.out.println(name+password);
        queryWrapper.eq("account_name", map.get("loginAccountName"))

                    .eq("password", map.get("loginPassword"));

        UserEntity userEntity = userService.getOne(queryWrapper);
        if (userEntity ==null)
            return R.error(-1,"没有找到用户名密码");
        else {
            return R.error(0,"用户名密码正确");
        }

    }



    @PostMapping("/registerUser")
    public R registerUser(@RequestParam Map<String, Object> map){
           QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
           queryWrapper.eq("account_name",map.get("accountName"))
                   .eq("mobile",map.get("mobile"))
                   .eq("password",map.get("password"));


           UserEntity userEntity = userService.getOne(queryWrapper);

        //注入到数据库
        boolean success = userService.save(userEntity);
        if (success){
            return R.error(-1,"注册成功");
        }else {
            return R.error(0,"注册失败");
        }



    }



    }

